﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlAgilityPack;
using Kooboo.HtmlFunc.Function;
using Kooboo.HtmlFunc.Providers;

namespace Kooboo.HtmlFunc.Analysis.Visitors
{
    public class HeadTagVisitor : VisitorBase
    {
        public HeadTagVisitor(VisitorContext context)
            : base(context)
        {
        }

        private bool setted = false;
        public override void VisitNode(HtmlNode node)
        {
            if (setted)
            {
                return;
            }

            if (node.Is("HEAD"))
            {
                setted = true;

                var headTag = Provider.Factory.GetProvider<IHeadTag>();
                headTag.Node = node;
                this.Context.Result.HeadTag = headTag;
            }
        }
    }
}
